﻿module move_tests
open Xunit
open FSharpChess
[<Fact>]
let test_illegmv() =
    Psn_tests.setup_pos3()
    Funcs.gm.SetMaterialCount()
    let oldgm = Funcs.gm.copy()
    let mv = Funcs.gm.CreateMove(Standard, 4, 59, 58, -1, 0)
    let ok = Move_do.DoMoveOK(mv,Funcs.gm)
    let eqb,eqm = Test_utils.psn_eql oldgm Funcs.gm
    let cond = not ok && eqb
    let mess = eqm
    Assert.True(cond,mess)
[<Fact>]
let test_legmv() =
    Psn_tests.setup_pos3()
    Funcs.gm.SetMaterialCount()
    let oldgm = Funcs.gm.copy()
    let mv = Funcs.gm.CreateMove(Standard, 2, 13, 6, 16, 0)
    let ok = Move_do.DoMoveOK(mv,Funcs.gm)
    Move_do.Undo(mv,Funcs.gm)
    let eqb,eqm = Test_utils.psn_eql oldgm Funcs.gm
    let cond = ok && eqb
    let mess = eqm
    Assert.True(cond,mess)
[<Fact>]
let test_checksnone() =
    Psn_tests.setup_pos3()
    Funcs.gm.SetMaterialCount()
    let checks = Move_gen.do_checks Funcs.gm 
    let cond = (List.length checks)=0
    let mess = "should be zero checks, have " + (List.length checks).ToString() 
    Assert.True(cond,mess)
[<Fact>]
let test_checkssome() =
    Psn_tests.setup_pos4()
    Funcs.gm.SetMaterialCount()
    let checks = Move_gen.do_checks Funcs.gm 
    let cond = (List.length checks)=3
    let mess = "should be 3 checks, have " + (List.length checks).ToString() 
    Assert.True(cond,mess)
[<Fact>]
let test_evas4() =
    Psn_tests.setup_pos4()
    Funcs.gm.SetMaterialCount()
    let checks = Move_gen.do_checks Funcs.gm
    let mvl = Move_gen.gen_evasions_pr Attack.PlayerBlack Funcs.gm checks
    let cond = (mvl.Count=1)
    let mess = "should be 1 evasion, have " + (mvl.Count).ToString() 
    Assert.True(cond,mess)
[<Fact>]
let test_evas5() =
    Psn_tests.setup_pos5()
    Funcs.gm.SetMaterialCount()
    let checks = Move_gen.do_checks Funcs.gm
    let mvl = Move_gen.gen_evasions_pr Attack.PlayerBlack Funcs.gm checks
    let cond = (mvl.Count=2)
    let mess = "should be 2 evasions, have " + (mvl.Count).ToString() 
    Assert.True(cond,mess)
[<Fact>]
let test_evas6() =
    Psn_tests.setup_pos6()
    Funcs.gm.SetMaterialCount()
    let checks = Move_gen.do_checks Funcs.gm
    let mvl = Move_gen.gen_evasions_pr Attack.PlayerBlack Funcs.gm checks
    let cond = (mvl.Count=3)
    let mess = "should be 3 evasions, have " + (mvl.Count).ToString() 
    Assert.True(cond,mess)
[<Fact>]
let test_evas7() =
    Psn_tests.setup_pos7()
    Funcs.gm.SetMaterialCount()
    let checks = Move_gen.do_checks Funcs.gm
    let mvl = Move_gen.gen_evasions_pr Attack.PlayerBlack Funcs.gm checks
    let cond = (mvl.Count=4)
    let mess = "should be 4 evasions, have " + (mvl.Count).ToString() 
    Assert.True(cond,mess)


